<%--
  Created by IntelliJ IDEA.
  User: sa手不太冷
  Date: 2022/9/13
  Time: 10:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="css/register.css" rel="stylesheet">

</head>
<body>
<div class="form-div">
    <div class="reg-content">
        <h1>欢迎注册</h1>
        <span>已有帐号？</span> <a href="login.jsp">登录</a>
    </div>
    <div style="color: red">${msg}</div>
    <form id="reg-form" action="/w9/registerServlet" method="post">
        <table>
            <tr>
                <td>用户名</td>
                <td class="inputs">
                    <input name="username" type="text" id="username">
                    <br>
                    <span id="username_err" class="err_msg" style="display: none">用户名不太受欢迎</span>
                </td>
            </tr>
            <tr>
                <td>密码</td>
                <td class="inputs">
                    <input name="password" type="password" id="password">
                    <br>
                    <span id="password_err" class="err_msg" style="display: none">密码格式有误</span>
                </td>
            </tr>


            <tr>
                <td>验证码</td>
                <td class="inputs">
                    <input name="checkCode" type="text" id="checkCode">
                    <img  id="changeCodeImg" src="/w9/checkCodeServlet">
                    <a href="" id="changeImg">看不清？</a>
                </td>
            </tr>

        </table>

        <div class="buttons">
            <input value="注 册" type="submit" id="reg_btn">
        </div>
        <br class="clear">
    </form>

</div>
<script src="js2/axios-0.18.0.js"></script>
<script>
    document.getElementById("changeImg").onclick=function (){
        //刷新 用日期做拼接 防止 具有缓存
        document.getElementById("changeCodeImg").src="/w9/checkCodeServlet?"+new Date().getMilliseconds();
    }

    document.getElementById("username").onblur=function (){

        console.log("11")
        let name = this.value;
        axios({
            method:"post",
            url:"http://localhost:8088/w9/checkNameServlet",
            data:"username="+name
        }).then(function (resp){
           if("ok"==resp.data){
                document.getElementById("username_err").style.display=''
           }else {
               document.getElementById("username_err").style.display='none'
           }
        })

    }



</script>
</body>
</html>
